#include "startup_thread.h"
#include "led_thread.h"
#include "malloc.h"
#include "usart_thread.h"
#include "motor_thread.h"
#include "config.h"
//led任务
static rt_thread_t led_thread = RT_NULL;


static rt_thread_t usart_recive_thread = RT_NULL;
static rt_thread_t usart_send_thread=RT_NULL;

static rt_thread_t motor_thread=RT_NULL;

#define MEM1_BLOCK_SIZE 32                             //内存块大小为32字节
#define MEM1_MAX_SIZE 2 * 1024                         //内存池大小
__align(32) uint8_t mem1base[MEM1_MAX_SIZE];           //内存池
uint16_t mem1mapbase[MEM1_MAX_SIZE / MEM1_BLOCK_SIZE]; //内存管理表
Mallco_dev mallco_dev;                                 //内存管理器

void startup_thread(void)
{
	my_mem_init(&mallco_dev, mem1base, mem1mapbase, MEM1_MAX_SIZE, MEM1_BLOCK_SIZE);
	Init_Model();
	//Init_Modelinfo();
	//led 任务																	
	led_thread = rt_thread_create("led",					   //线程名字
									led_thread_entry,		             //线程入口函数
									RT_NULL,				                 //参数
									led_thread_stack_size,	         //线程栈大小
									led_thread_priority,	           //线程优先级
									led_thread_tick);		             //线程时间片							
	if(led_thread != RT_NULL) rt_thread_startup(led_thread);
	
	usart_recive_thread = rt_thread_create("uart_revice",					//线程名字
									Usart_Receive_thread_entry,		  //线程入口函数
									RT_NULL,				                  //参数
								  usart_Recive_thread_stack_size,	//线程栈大小
									usart_Recive_thread_priority,	  //线程优先级
									usart_Recive_thread_tick);		    //线程时间片							
	if(usart_recive_thread != RT_NULL) rt_thread_startup(usart_recive_thread);
	
	usart_send_thread = rt_thread_create("uart1_send",					//线程名字
									Usart_Send_thread_entry,		                //线程入口函数
									RT_NULL,				                            //参数
									usart_Send_thread_stack_size,	            //线程栈大小
									usart_Send_thread_priority,	              //线程优先级
									usart_Send_thread_tick);		                //线程时间片							
	if(usart_send_thread != RT_NULL) rt_thread_startup(usart_send_thread);
	
	motor_thread = rt_thread_create("motor",					//线程名字
									motor_thread_entry,		                //线程入口函数
									RT_NULL,				                            //参数
									Motor_thread_stack_size,	            //线程栈大小
									Motor_thread_priority,	              //线程优先级
									Motor_thread_tick);		                //线程时间片							
	if(motor_thread != RT_NULL) rt_thread_startup(motor_thread);

}
